package com.six.goods.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.six.core.entity.Brand;
import com.six.core.vo.Result;
import com.six.goods.mapper.BrandMapper;
import com.six.goods.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author wang
* @description 针对表【sto_brand】的数据库操作Service实现
* @createDate 2023-02-27 15:19:23
*/
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    //分页
    @Override
    public Result seleAllBrand(Integer currentPage, Integer pageSize, Brand brand) {
        PageHelper.startPage(currentPage,pageSize);
        List<Brand> brands = brandMapper.selectBrand(brand);
        PageInfo<Brand> pageInfo=new PageInfo<>(brands);
        if (pageInfo != null){
            return new Result(2000 ,"查询成功",pageInfo);
        }
       return new Result(5000,"查询失败");
    }

    /**
     * 修改品牌
     * @param brand
     * @return
     */
    @Override
    public Result updateBrand(Brand brand) {
        int i = brandMapper.updateById(brand);
        if (i>0){
            return new Result(2000,"修改品牌 成功");
        }else {
            return new Result(5000, "修改品牌 失败");
        }
    }

    /**
     * 增加品牌
     * @param brand
     * @return
     */
    @Override
    public Result insertBrand(Brand brand) {
        int insert = brandMapper.insert(brand);
        if (insert>0){
            return new Result(2000,"增加品牌成功");
        }else {
            return new Result(5000, "增加品牌 失败");
        }
    }
    /**
     * 删除品牌
     * @param id
     * @return
     */
    @Override
    public Result deleteBrand(Integer id) {
        int i = brandMapper.deleteById(id);
        if (i>0){
            return new Result(2000,"删除品牌成功");
        }else {
            return new Result(5000, "删除品牌 失败");
        }

    }

    @Override
    public Result selectAllBrand() {
        List<Brand> brands = brandMapper.selectBrand(null);
        if (brands!=null){
            return new Result(2000,"查询成功",brands);
        }else {
            return new Result(5000, "查询失败");
        }
    }

    @Override
    public Brand seleBybrandname(Brand brand) {
        Brand brand1 = brandMapper.seleBybrandname(brand);
        return brand1;
    }
}




